package com.yxq.mdt.app.utils;

import android.content.Context;

import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXMiniProgramObject;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.yxq.mdt.app.BuildConfig;
import com.yxq.mdt.app.constant.Constant;

/**
 * @author L
 * @time 2019-12-13
 * @describe 微信工具$
 */
public class WxUtils {
    /**
     * 跳转微信小程序
     *
     * @param context
     */
    public static void IntentWxSmallApp(Context context, String path) {

        IWXAPI api = WXAPIFactory.createWXAPI(context, Constant.WECHAT_ID);

        WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
        req.userName = Constant.WECHAT_SMALL_APP_ID; // 填小程序原始id
        req.path = path; //拉起小程序页面的可带参路径，不填默认拉起小程序首页
        if ("release".equals(BuildConfig.RELEASE)) {
            req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;//  正式版
        } else if ("release_pre".equals(BuildConfig.RELEASE)) {
            req.miniprogramType = WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_PREVIEW;// 体验版
        } else {
            req.miniprogramType = WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_PREVIEW;// 体验版
        }
        api.sendReq(req);
    }

    public static void IntentShare() {
//        WXMiniProgramObject miniProgramObj = new WXMiniProgramObject();
//        miniProgramObj.webpageUrl = "http://www.qq.com"; // 兼容低版本的网页链接
//        miniProgramObj.miniprogramType = WXMiniProgramObject.MINIPTOGRAM_TYPE_RELEASE;// 正式版:0，测试版:1，体验版:2
//        miniProgramObj.userName = "gh_d43f693ca31f";     // 小程序原始id
//        miniProgramObj.path = "/pages/media";            //小程序页面路径
//        WXMediaMessage msg = new WXMediaMessage(miniProgramObj);
//        msg.title = "小程序消息Title";                    // 小程序消息title
//        msg.description = "小程序消息Desc";               // 小程序消息desc
//        msg.thumbData = getThumb();                      // 小程序消息封面图片，小于128k
//
//        SendMessageToWX.Req req = new SendMessageToWX.Req();
//        req.transaction = buildTransaction("webpage");
//        req.message = msg;
//        req.scene = SendMessageToWX.Req.WXSceneSession;  // 目前支持会话
//        api.sendReq(req);
    }
}
